<?php
JHtml::_('behavior.mootools');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.multiselect');

$usertype = $this->usertype;
$mailgroup = $this->mailgroup;
$area = $this->area;
$pref = $this->pref;
//echo "<pre>";print_r($pref);echo "</pre>";
$rows = $this->rows;
?>
<div class="popup">
   <form action="<?php echo JRoute::_('index.php?option=com_popup&view=bg');?>" name="adminForm" id="adminForm" class="form-popup recipients" method="post">
      <!-- filter -->
      <div id="filter">
         <div class="row">
            <p class="col">
               <label>ユーザタイプ</label>
               <select name="usertype" id="usertype" class="medium">
               <option value="0" selected="selected">全て...</option>
               <?php
                    $usertype_search = $this->usertype_search;
                    foreach($usertype as $value){
               ?>
               <option value="<?php echo $value->id; ?>" <?php $temp = isset($usertype_search) ? $usertype_search : false;if ($temp == $value->id) { echo ' selected="selected"';} ?> ><?php echo $value->title; ?></option>
               <?php
                    }
               ?>              
               </select>              
            </p>
            <p class="col">
               <label>メールグループ</label>
               <select name="mailgroup" id="mailgroup" class="medium">
                  <option value="0" selected="selected">全て...</option>
                  <?php
                    $mailgroup_search = $this->mailgroup_search;
                    foreach($mailgroup as $value){
                  ?>
                  <option value="<?php echo $value->MAGR_CODE; ?>" <?php $temp = isset($mailgroup_search) ? $mailgroup_search : false;if ($temp == $value->MAGR_CODE) { echo ' selected="selected"';} ?> ><?php echo $value->MAGR_NAME; ?></option>
                  <?php
                    }
                  ?>
               </select>
            </p>
         </div>
         <div class="row">
            <p class="col">
               <label>地区</label>
               <select name="area" id="area" class="medium">
                  <option value="0" selected="selected">全て...</option>
                  <?php
                    $area_search = $this->area_search;
                    foreach($area as $value){
                  ?>
                  <option value="<?php echo $value->AREA_CODE; ?>" <?php $temp = isset($area_search) ? $area_search : false;if ($temp == $value->AREA_CODE) { echo ' selected="selected"';} ?> >
                  <?php echo $value->AREA_NAME; ?></option>
                  <?php
                    }
                  ?>
               </select>
            </p>
            <p class="col">
               <label>都道府県</label>
               <span id="area_pref">
                   <select name="pref" id="pref" class="medium">
                      <option value="0" selected="selected">全て...</option>
                      <?php 
                        $pref_search = $this->pref_search;              
                        foreach($pref as $value){                       
                      ?>
                      <option value="<?php echo $value->PREF_CODE; ?>" <?php $temp = isset($pref_search) ? $pref_search : false;if ($temp == $value->PREF_CODE) { echo ' selected="selected"';} ?> ><?php echo $value->PREF_NAME; ?></option>
                      <?php      
                        }                 
                      ?>
                   </select>
               </span>
            </p>
         </div>
         <div class="row">
            <p class="col">
               <label>センター．クラブ名</label>
               <input class="big" type="text" name="ocba_name" id="ocba_name" value="<?php echo $this->ocba_name; ?>" />
            </p>
            <p class="col right">
               <button type="submit"><?php echo JText::_('検索'); ?></button>
	           <button type="button" onclick="document.id('ocba_name').value='';document.id('usertype').value=0;document.id('mailgroup').value=0;document.id('area').value=0;document.id('pref').value=0;this.form.submit();"><?php echo JText::_('クリア'); ?></button>
               
            </p>
         </div>
      </div>
      <!-- end filter -->
      <!-- table -->
      <div class="clearfix"></div>
      <table>
         <thead>
            <th class="center"><input name="toggle" type="checkbox" onclick="checkAll(<?php echo count($this->rows); ?>)" /></th>
            <th>送信先コード</th>
            <th>送信先名</th>
         </thead>
         <tbody>
         <?php
         if($rows != null){
            foreach($rows as $value){
         ?>
            <tr>
               <td class="center"><input type="checkbox" id="cb<?php echo $value->OCBA_CODE; ?>" name="cid[]" value="1"/></td>
               <td><?php echo $value->OCBA_CODE; ?></td>
               <td><?php echo $value->OCBA_NAME; ?></td>
            </tr>
         <?php
            }
         }else{
         ?>
            <tr>
                <td class="center" colspan="3">データは見つかりませんでした</td>
            </tr>
         <?php
            }            
         ?>     
         </tbody>
         
      </table>
      <input type="hidden" name="task" value="" />
      <input type="hidden" name="boxchecked" value="0" />
   </form>
</div>
<script language="javascript">
	jq(document).ready(function(){
		jq("#area").change(function(){
			var id = document.getElementById("area").value;
			var url = "index.php?option=com_popup&task=selectArea";
            var data = 'area_code='+id;
            var request = new Request({
                            url: url,
                            method:'get',
                            data: data,
                            onSuccess: function(responseText){
                               document.getElementById('area_pref').innerHTML = responseText;
                            }
                }).send();		
		})
			
	})
</script>
